package com.kaigejava.iterator.iterator;

import com.kaigejava.iterator.MenuItem;

/**
 * Created by kaigejava on 2019/9/7.
 * 实现了iterator的早餐店
 */
public class DinerIterator implements Iterator {
    private int position;
    private int numberOfItems;
    private  MenuItem[] menuItems;

    public DinerIterator(int numberOfItems, MenuItem[] menuItems) {
        this.menuItems = menuItems;
        this.numberOfItems = numberOfItems;
        position = 0;
    }

    @Override
    public boolean hasNext() {
        if (position < numberOfItems) {
            return true;
        }

        return false;
    }

    @Override
    public Object next() {
        MenuItem menuItem = menuItems[position];
        position++;
        return menuItem;
    }
}
